package com.example.medical.controller.leadership;

import com.example.medical.entity.dto.LoginDto;
import com.example.medical.entity.dto.SaveLeadershipDto;
import com.example.medical.entity.dto.UpdatePasswordDto;
import com.example.medical.service.LeadershipService;
import com.example.medical.utils.common.enums.Code;
import com.example.medical.utils.common.result.Result;
import com.example.medical.utils.config.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/leadership/leadership")
public class LeadershipController {

    @Autowired
    private LeadershipService leadershipService;

    @PostMapping("/leadership_login")
    public Result LeadershipLogin(@RequestBody LoginDto dto){
        return leadershipService.LeadershipLogin(dto);
    }

    @PostMapping("/save_leadership")
    public Result SaveLeadership(@RequestBody SaveLeadershipDto dto){
        return leadershipService.SaveLeadership(dto);
    }

    @PostMapping("/update_leadership_password")
    public Result UpdateLeadershipPassword(@RequestBody UpdatePasswordDto dto){
        return leadershipService.UpdateLeadershipPassword(dto);
    }

    @GetMapping("/get_leadership")
    public Result GetLeadership(){
        return Result.okResult(leadershipService.getById(BaseContext.getCurrentId()));
    }

    @PostMapping("/update_leadership_detail")
    public Result UpdateLeadershipDetail(@RequestParam("file")MultipartFile file,
                                         @RequestParam("sex") Integer sex) throws Exception {
        return leadershipService.UpdateLeadershipDetail(file,sex);
    }

    @GetMapping("/leadership_logout")
    public Result LeadershipLogout(){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        BaseContext.removeCurrentId();
        return Result.okResult(Code.SUCCESS);
    }

}
